<template>
  <div id="pinglun">
    <div class="daohang">
      <!-- <button @click='prev'>返回上一级</button> -->
 <!-- <router-link to="/personage"> 返回订单 </router-link>-->
   
 
    </div> 

    <div class="pinglun-top-area">  <router-link to="/personageindex"> <img src="../../assets/shouye.svg" width="20" height="20"></router-link>就医经验  </div>
    <!-- = {{doctor.ddname}} v-for="doctor in doctors" :key="doctor.ddid"<h3>{{time|formatDate}}</h3>-->
    <div class="pinglun-area border">
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="选择主治医师">
          <el-select v-model="form.ddid" placeholder="请选择医师">
            <div>
              <el-option
                v-for="doctor in doctors"
                :key="doctor.ddid"
                :label="doctor.ddname"
                :value="doctor.ddid"
              ></el-option>

              <!-- <el-option label= {{doctor.ddname}} value="shanghai">{{doctor.ddname}}</el-option> v-model="form.uuid"-->
              <!-- <el-option label="2" value="beijing"></el-option> -->
            </div>
          </el-select>
        </el-form-item>
        <el-form-item label="评价星数">
          <el-radio-group v-model="form.pxingji">
            <el-radio label="1"></el-radio>
            <el-radio label="2"></el-radio>
            <el-radio label="3"></el-radio>
            <el-radio label="4"></el-radio>
            <el-radio label="5"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="留言">
          <el-input type="textarea" v-model="form.pcontent"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
     time:Date.parse(new Date()),
      uname: window.localStorage.getItem("uname"),
      uidcard: window.localStorage.getItem("uidcard"),
      users: {},

      user: {
        uname: window.localStorage.getItem("uname"),
        uidcard: window.localStorage.getItem("uidcard")
      },

      useruid: "",
      ddname: "",
      pdate: "",
      form: {
        pdate:Date.parse(new Date()),
        ddid: "",
        uname: window.localStorage.getItem("uname"),
        uidcard: window.localStorage.getItem("uidcard"),
        pxingji: "",
        pcontent: ""
      },
      doctors: ""
    };
    
  },
  mounted: function() {
    this.getAllDoctor();
    this.getUser();
  },
   filters: {
                formatDate: function (value) {
                let date = new Date(value);
                let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? ('0' + MM) : MM;
                let d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                let h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                let m = date.getMinutes();
                m = m < 10 ? ('0' + m) : m;
                let s = date.getSeconds();
                s = s < 10 ? ('0' + s) : s;
               return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
              }
            },
  methods: {
    goBack() {
        console.log('go back');
      },
      prev(){

this.$router.go(-1)

},
    onSubmit() {
      console.log("submit!");
      // console.log(this.form.uname);
      // console.log(this.form.uidcard);
      // console.log(this.form.ddid);
      // console.log(this.form.pdate);
      // console.log(this.form.pcontent);
      // console.log(this.form.pxingji);
      // console.log(this.form);

      this.$http
        .post("http://localhost:8001/pinglun/addpinglun", this.form)
        .then(function(data) {
          if (data.bodyText == "success") {
            console.log(data.bodyText);

          
                 this.$message({
          showClose: true,
          message: '评论成功',
          type: 'success'
        });
          } else {
           
               this.$message({
          showClose: true,
          message: '评论失败',
          type: 'error'
        });
          }
          // console.log(data.bodyText);
          // console.log(data.bodyText);
        });
    },
    getAllDoctor() {
      console.log("测试" + this.user + this.uname);
      this.$http
        .get("http://localhost:8001/doctor/getalldoctor")
        .then(function(data) {
          this.doctors = data.body;
          // console.log(this.doctors);
        });
    },

    getUser: function() {
      console.log("测试" + this.user + this.uname);
      this.$http
        .post("http://localhost:8001/user/getuser", this.user)
        .then(function(data) {
          this.users = data.body;
          this.useruid = this.users.uuid;
          // console.log("测试" + this.users);
          // console.log("测试" + this.users.uname);
          // console.log("测试" + this.useruid);
        });
    }
  }
};
</script>
<style scoped>
.daohang{
  color: #919396;
  font-size: 15px;
  position: absolute;
  top: -50px;
  left: 10px;
}
.pinglun-top-area {
  position: absolute;
  top: 20px;
  left: 10px;
  font-size: 20px;
  color: #448aff;
  line-height: 22px;
}
.pinglun-area {
  width: 500px;
  height: 400px;
  position: absolute;
  line-height: 12px;
  left: 50px;
  top: 85px;
  background-color: #F5F5F5;
}
.border {
  /* border: 1px solid red; */
}
</style>

